import { Node } from '@topology/core'
const iszjIcon = require('@/assets/中介.jpg')
const feibixuanIcon = require('@/assets/非必选.jpg')
function setChildNode(data, canvas) {
  try {
    let image1 = ''
    let image2 = ''
    if (data.data.isIntervene === 1) {
      image1 = iszjIcon
    }
    // if (data.data.process === 1) {
    //   image2 = feixuanIcon
    // }
    if (data.data.process === 2) {
      image2 = feibixuanIcon
    }
    // 父节点
    const child1 = {
      text: '',
      rect: {
        width: 25,
        height: 47,
        x: data.rect.x,
        y: data.rect.y + data.rect.height
      },
      name: 'image',
      image: image1
    }
    const childNode1 = new Node(child1)
    // 设置子节点相对父节点属性
    childNode1.rectInParent = {
      x: '-35%',
      y: -5,
      width: 25,
      height: 47
    }
    // 创建状态节点属性
    const child2 = {
      text: '',
      rect: {
        width: 30,
        height: 30,
        x: data.rect.x + data.rect.width - 30,
        y: data.rect.y + data.rect.height - 30
      },
      name: 'image',
      image: image2
    }
    const childNode2 = new Node(child2)
    // 设置子节点相对父节点属性
    childNode2.rectInParent = {
      x: '99%',
      y: -5,
      width: 30,
      height: 30
    }
    // 设置children方法
    data.setChild([childNode1, childNode2])
    canvas.render()
  } catch (e) {
    console.log(e)
  }
}

export {
  setChildNode
}
